<template>
	<view class="detail">
		<view class="cover" v-if="detail.cover_image">
			<image :src="detail.cover_image" mode=""></image>
		</view>
		<view class="content-box">
			<rich-text :nodes="htmlString"></rich-text>
		</view>
		<view class="time">{{detail.update_time_text}}</view>
	</view>
</template>

<script>
	import Request from '../../common/request.js';
	
	export default {
		data() {
			return {
				title: '文章详情',
				detail: '',
				htmlString: '',
				id: ''
			};
		},
		onLoad(options) {
			this.id = options.id;
			uni.setNavigationBarTitle({
				title: options.title
			})
			this.getDetail();
		},
		methods: {
			getDetail () {
				var that = this;
				var params = {
					url: 'article/detail',
					data: {id: that.id},
					sCallback: function(res) {
						that.detail = res.data;
						uni.setNavigationBarTitle({
							title: res.data.title
						})
						that.htmlString = res.data.content.replace(/\\/g, "").replace(/<img/g, "<img style=\"max-width:100%;\"");
					}
				}
				
				Request.send(params);
			}
		}
	}
</script>

<style>
	page{
		background: #fff;
	}
	
	.cover{
		text-align: center;
	}
	
	.time{
		text-align: right;
		margin-top: 40upx;
		padding-right: 20upx;
		color: #333;
	}
</style>
